Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next

Copying an Offscreen Image Into a Window

After preparing an image in the offscreen graphics world, your application must use SetGWorld to restore the active window as the current graphics port, as illustrated in Listing 6-1 .

To copy the image from an offscreen graphics world into a window, use the CopyBits procedure. Specify the offscreen graphics world as the source image for CopyBits , and specify the window as its destination. When using CopyBits , you must coerce the offscreen graphics world's GWorldPtr data type to a data structure of type GrafPtr . Similarly, whenever a color graphics port is your destination, you must coerce the window's CGrafPtr data type to a data structure of type GrafPtr . (The CopyBits procedure is described in the chapter "QuickDraw Drawing.")

As long as you're drawing into an offscreen graphics world or copying the image out of it, you must leave its pixel image locked. When you are finished drawing into and copying from an offscreen graphics world, use the UnlockPixels procedure. To help prevent heap fragmentation, the UnlockPixels procedure allows the Memory Manager to move the base address for the offscreen pixel image. (For more information about Macintosh memory management, see Inside Macintosh: Memory .)

Finally, call the DisposeGWorld procedure when your application no longer needs the pixel image associated with this offscreen graphics world, as illustrated in Listing 6-1 .


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next